/**
* Template project. Does nothing but take arguments
* and print them out.
* \author Shekhar S. Chandra, 2007-9
*/
#include <stdlib.h>
#include <stdio.h>

#include "contrib/libtarga.h"

///Globals
const int size = 256;

///Function Prototypes

int main(int argc, char *argv[])
{
    unsigned char* targaimage;
    int j, k, wdt = size, hgt = size;

    targaimage = (unsigned char*) tga_create(wdt, hgt, TGA_TRUECOLOR_32);

    for(j = 0; j < wdt; j ++)
        for(k = 0; k < hgt; k ++)
        {
            targaimage[(j*wdt + k)*4] = j*wdt + k;
            targaimage[(j*wdt + k)*4 + 1] = j*wdt + k;
            targaimage[(j*wdt + k)*4 + 2] = j*wdt + k;
            targaimage[(j*wdt + k)*4 + 3] = 255;
        }

    printf("Writing Image!\n");
    if (!tga_write_raw("output.tga", wdt, hgt, targaimage, TGA_TRUECOLOR_32))
    {
        printf("Failed to write image!\n");
        printf(tga_error_string(tga_get_last_error()));
    }

    free(targaimage);
    return EXIT_SUCCESS;
}
